<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="initial-scale=1.0; maximum-scale=1.0; user-scalable=no;">
<meta name="format-detection" content="telephone=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="msapplication-tap-highlight" content="no">
<script src="pageRc/jquery-1.9.1.min.js"></script>
<script src="pageRc/json2.js"></script>
 
<style type="text/css">
#main_table
{
	MARGIN-LEFT: 36px;
}

.msgType {
	padding: 3px;
	font-family: verdana, arial, sans-serif;
	font-size: 13px;
	font-weight: bold;
}

.reqType {
	margin-top: 20px;
	margin-bottom: 5px;
}

table {
	font-family: verdana, arial, sans-serif;
	font-size: 11px;
	color: #333333;
	border-width: 1px;
	border-color: #999999;
	border-collapse: collapse;
}

table th {
	background-color: #c3dde0;
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #a9c6c9;
}

table tr {
	background-color: #d4e3e5;
}

table td {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #a9c6c9;
}
</style>

<title>接口报文测试-1</title>
<script> 
<%
String commonPath = request.getContextPath();
String extPath = request.getContextPath();
String extBasePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+extPath+"/";
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort();
%>
$(function(){
	// 
 		  $("#sendURL").val(localStorage.getItem('sendURL'));
		  $("#sendMsg").val(localStorage.getItem('sendMsg'));
})
  function sendMsg(){
  		var sendURL = $("#sendURL").val();
  		if(sendURL==null ||sendURL==""){
  			 alert("发送URL地址不能为空！");
  			return;
  		}
  		var sendMsg = $("#sendMsg").val();
  		if(sendMsg==null ||sendMsg==""){
  			 alert("发送报文不能为空！");
  			return;
  		}
  		
  		
  	    var fileBase64 = $("#fileBase64Data").val();
  	    var fileName = $("#fileName").val();
   		
  	    var json = eval('(' +  sendMsg + ')');
  	    json.body.fileBase64Data = fileBase64;
  	    json.body.fileName = fileName;
  	    
  	    sendMsg = JSON.stringify(json);
  	    console.log(sendMsg)
  	    localStorage.setItem('sendURL',sendURL);
		localStorage.setItem('sendMsg',sendMsg);
  		 
  	    
  		$.ajax({
			    	type: 'POST',
			        url: "<%=commonPath%>/"+sendURL ,
				    data:sendMsg,
				    headers:{
		                "Infoq":"ch=linkusWeb;e=p"
		            },
				    dataType: 'text',
			        success: function(data) {  
			           $('#revMsg').val("");
			           $('#revMsg').val(data);
			        },
			        error:function(data){
			           alert("查询异常，请联系系统管理员！");
			        }
			 });   	
  
  }
  
  //加载默认值
  function loadDefaultData(){
	  var sendURL = "ns0/sys/login.do";
	  var sendMsg = '{"head":{},"body":{userNo:"1001",password:"1"}}';
	  $("#sendURL").val(sendURL);
	  $("#sendMsg").val(sendMsg);
  }
  //添加报文历史信息
  function addHistoryInfor(){
	  var sendurl = $("#sendURL").val();
	  var sendmsg = $("#sendMsg").val();
	  var revmsg = $("#revMsg").val();
	  sendmsg = encodeURIComponent(encodeURIComponent(sendmsg));
	  alert(sendmsg)
	  $.ajax({
	    	type: 'POST',
	        url: "<%=commonPath%>/hpage/addMsgInfor.do" ,
		    data:'{"sendurl":"'+sendurl+'","sendmsg":"'+sendmsg+'","revmsg":"'+revmsg+'"}',
		    dataType: 'text',
	        success: function(data) {
	          var jsonsData = JSON.parse(data);
	          if(jsonsData.STATUS=='0'){
	        	  layer.alert(jsonsData.MSG); 
	        	 
	          }else{
	             layer.closeAll();
	             layer.alert(jsonsData.MSG);
	          }
	        },
	        error:function(data){
	           layer.closeAll();
	           layer.alert("网络连接失败，请重试!");
	        }
 	    }); 
  }
</script>
</head>
<body>
	访问地址:<input id="sendURL" type="text" style="width:50%" autofocus  required="required" placeholder="请输入访问地址" />
	<input type="button" onclick="javascript:loadDefaultData();" value="加载默认报文" />
	<input type="button" onclick="javascript:addHistoryInfor();" value="保存历史" /><br/>
	<br/>
	发送报文:<textarea id="sendMsg" rows="8" cols="100"  placeholder="请输入发送报文"  ></textarea>
	<input type="button" onclick="javascript:sendMsg();"  value="发送报文" /><br/>
	<hr /><br />
	接收报文:<textarea id="revMsg" rows="8" cols="100"></textarea>
	<p></p>
	<input name="fileBase64Data" id="fileBase64Data">
		<input name="fileName" id="fileName">
	
     文件:<input id="file1" type="file" name="file1"/> 
     
                     
<script type="text/javascript">
$(document).ready(function(){
	  $("#file1").change(function(){
	    var v = $(this).val();
	    var reader = new FileReader();
	    $("#fileName").val(this.files[0].name);
	    reader.readAsDataURL(this.files[0]);
	    reader.onload = function(e){
 	      $('#fileBase64Data').val(e.target.result);
	    };
	  });
	});
	</script>
    </script>
  </body>
</html>